import logging
import os
from datetime import datetime

now = datetime.now()
str_time = now.strftime('%Y-%m-%d %H_%M_%S')

from appium_qiyeweixin.until.until import join_path

# 创建记录器
logger = logging.getLogger(os.path.basename(__file__))
logger.setLevel(logging.DEBUG)

# 创建流处理器，控制台输出信息
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)

# 创建文件处理器
file_handler = logging.FileHandler(filename=join_path("log", f"{str_time}.log"))
file_handler.setLevel(logging.DEBUG)

# 创建格式器
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')

# 添加格式器到文件处理器中
file_handler.setFormatter(formatter)
stream_handler.setFormatter(formatter)

# 添加处理器到记录器中
logger.addHandler(file_handler)
logger.addHandler(stream_handler)
